<template>
  <div>
    <div class="ser_div">
      <el-row>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 订单号 </el-col>
            <el-col :span="16">
              <el-input v-model="ser.order_number" type="number"></el-input>
            </el-col>
          </el-row>
        </el-col>
        <!-- <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 流水号 </el-col>
            <el-col :span="16">
              <el-input v-model="ser.serial_number"></el-input>
            </el-col>
          </el-row>
        </el-col> -->
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 客户 </el-col>
            <el-col :span="16">
              <el-select
                filterable
                clearable
                v-model="ser.customer_id"
                placeholder="请选择客户"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in CustomerList"
                  :key="index"
                  :label="item.customer_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <!-- <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 产品 </el-col>
            <el-col :span="16">
              <el-select
                filterable
                clearable
                v-model="ser.product_id"
                @change="product_id_change"
                placeholder="请选择产品"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in productList"
                  :key="index"
                  :label="item.product_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 型号 </el-col>
            <el-col :span="16">
              <el-select
                filterable
                v-model="ser.model_number_id"
                placeholder="请选择型号"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in ModelNumberList"
                  :key="index"
                  :label="item.model_number"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 仓库 </el-col>
            <el-col :span="16">
              <el-select v-model="ser.warehouse_id" clearable  @change="Warehouse_change" placeholder="请选择仓库">
              <el-option v-for="item in WarehouseList" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>

            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 货架 </el-col>
            <el-col :span="16">
              <el-select v-model="ser.goods_shelf_id" clearable placeholder="请选择货架">
              <el-option v-for="item in goods_shelfList" :key="item.goods_shelf_id" :label="item.name"
                :value="item.goods_shelf_id">
              </el-option>
            </el-select>

            </el-col>
          </el-row>
        </el-col> -->
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 状态 </el-col>
            <el-col :span="16">
              <el-select
                v-model="ser.logistics_status"
                placeholder="请选择物流状态"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in logistics_statuslist"
                  :key="index"
                  :label="item.lable"
                  :value="item.status"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 入库日期范围 </el-col>
            <el-col :span="16">
              <el-date-picker
                v-model="order_data"
                @change="order_data_change"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              >
              </el-date-picker>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-button @click="search(0)" class="add_btn">查询</el-button>
          <el-button @click="searchreset" class="add_btn">重置</el-button>
          <el-button @click="search(2)" class="add_btn">导出</el-button>
          <el-button type="primary" @click="Dayin_chuhuo(1)" class="add_btn"
            >打印出货单</el-button
          >
          <!-- <el-button type="primary" @click="push_daifahuo()" class="add_btn"
            >设置为待发货</el-button
          > -->
          <!-- <el-button type="primary" @click="push_siji()" class="add_btn"
            >指派司机</el-button
          > -->

        </el-col>
      </el-row>
    </div>

    <el-table
      :data="dataList"
      v-horizontal-scroll="'always'"
      stripe
      v-loading="loading"
      :row-style="tableRowClassName"
     :row-key="getRowKeys"
      reserve-selection
       ref="multipleTable"
      style="width: 100%"
      @selection-change="handleSelectionChange"  border>
      <el-table-column type="selection" :reserve-selection="true"> </el-table-column>
      <el-table-column prop="id" label="ID" width="60"> </el-table-column>
      <el-table-column prop="order_id" label="订单ID" width="60">
      </el-table-column>
      <el-table-column prop="warehouse_entry_time" label="入库日期" width="100">
      </el-table-column>
      <!-- <el-table-column label="订单日期" width="100">
        <template slot-scope="scope">
          {{ formatterTime(scope.row.order_smiple.order_date) }}
        </template>
      </el-table-column> -->
      <el-table-column label="客户" width="80">
        <template slot-scope="scope">
          {{ scope.row.customer ? scope.row.customer.customer_name : "" }}
        </template>
      </el-table-column>
      <el-table-column label="业主地址" width="100">
        <template slot-scope="scope">
          {{ scope.row.order_smiple.customer_name }}
        </template>
      </el-table-column>
      <el-table-column label="业主电话" width="100">
        <template slot-scope="scope">
          {{ scope.row.order_smiple.customer_phone }}
        </template>
      </el-table-column>

      <el-table-column label="订单号" width="100">
        <template slot-scope="scope">
          {{ scope.row.order_number }}
        </template>
      </el-table-column>
      <el-table-column prop="receivables" label="应收款" width="80">
        <template slot-scope="scope">
          {{ scope.row.order_smiple?scope.row.order_smiple.receivables:"" }}
        </template>
      </el-table-column>
      <el-table-column prop="received" label="已收款" width="80">
        <template slot-scope="scope">
          {{ scope.row.order_smiple?scope.row.order_smiple.received:"" }}
        </template>
      </el-table-column>
      <el-table-column label="尾款" width="80">
        <template slot-scope="scope">
          {{ scope.row.order_smiple?scope.row.order_smiple.owe_price:"" }}
        </template>
      </el-table-column>
      <el-table-column label="备注" width="120">
        <template slot-scope="scope">
          {{ scope.row.order_smiple?scope.row.order_smiple.remark:"" }}
        </template>
      </el-table-column>
      <el-table-column label="代发备注" width="120">
        <template slot-scope="scope">
          {{ scope.row.order_smiple?scope.row.order_smiple.daifa_remark:"" }}
        </template>
      </el-table-column>
      
      <el-table-column label="发货司机" width="100">
        <template slot-scope="scope">
          {{ scope.row.user?scope.row.user.company_name:"" }}
        </template>
      </el-table-column>
      <el-table-column prop="logistics_status" label="发货状态" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.logistics_status == 1" style="color: #dd8211"
            >待发货</span
          >
          <span v-if="scope.row.logistics_status == 2" style="color: #f1420d"
            >未发货</span
          >
          <span v-if="scope.row.logistics_status == 4" style="color: #b47425"
            >部分待发货</span
          >
          <span v-if="scope.row.logistics_status == 5" style="color: #b47425"
            >部分未发货</span
          >
          <span v-if="scope.row.logistics_status == 3" style="color: #0ca747"
            >已发货</span
          >
          <span
            v-if="scope.row.logistics_status == 6"
            style="color: #4e4a4c; font-weight: bold"
            >已退货</span
          >
        </template>
      </el-table-column>
      <!-- <el-table-column label="退换货" width="120">
        <template slot-scope="scope">
          {{
            scope.row.return_status == 1
              ? "退货"
              : scope.row.return_status == 2
              ? "换货"
              : "正常"
          }}
        </template>
      </el-table-column> -->
      <el-table-column label="物流信息" width="120">
        <template slot-scope="scope">
          {{ scope.row.logistics_info }}
        </template>
      </el-table-column>
      <el-table-column label="仓库" width="120">
        <template slot-scope="scope">
          {{ scope.row.warehouse ? scope.row.warehouse.warehouse_name : "" }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="90" fixed="right">
        <template slot-scope="scope">
          <el-dropdown trigger="click">
            <el-button type="primary" size="small">
              操作<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <el-button type="text" @click="set_product(scope.row.id)"
                  >产品详情</el-button
                >
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button   v-if="scope.row.is_deduct_money === 2" type="text" @click="handleOpen(scope.row.id)">
                  扣款</el-button
                >
              </el-dropdown-item>
              <el-dropdown-item>
                <el-popconfirm
                  v-if="scope.row.is_deduct_money === 1"
                  confirm-button-text="好的"
                  cancel-button-text="不用了"
                  icon-color="red"
                  title="确定将此扣款进行取消吗？"
                  @confirm="koukuan_2(scope.row.id, 2)"
                >
                  <el-button slot="reference" type="text"> 取消扣款</el-button>
                </el-popconfirm>
              </el-dropdown-item>
              <!-- <el-dropdown-item>
                <el-button
                  @click="diaohuo(scope.row)"
                  type="text"
                  :disabled="scope.row.logistics_status != 2"
                  >调货</el-button
                >
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button
                  style="padding-left: 8px"
                  @click="diaohuojilu(scope.row)"
                  :disabled="scope.row.stock_allocation_log.length == 0"
                  type="text"
                  >调货记录</el-button
                >
              </el-dropdown-item> -->
              <el-dropdown-item>
                <!-- <el-popconfirm
                  confirm-button-text="好的"
                  cancel-button-text="不用了"
                  icon-color="red"
                  title="是否设置为待发货状态？"
                  @confirm="push_daifahuos(scope.row.id)"
                >
                  <el-button
                   
                    :disabled="
                    scope.row.logistics_status == 1 ||
                    scope.row.logistics_status == 3
                  "
                    type="text"
                    @click="push_daifahuos(scope.row.id)"
                  >
                  设置为待发货</el-button
                  >
                  
                </el-popconfirm> -->
                <el-button
                   
                    :disabled="
                    scope.row.logistics_status == 1 ||
                    scope.row.logistics_status == 3
                  "
                    type="text"
                    @click="push_daifahuos(scope.row.id)"
                  >
                  设置为待发货</el-button
                  >
              </el-dropdown-item>
              <el-dropdown-item>
                <el-popconfirm
                  confirm-button-text="好的"
                  cancel-button-text="不用了"
                  icon-color="red"
                  title="是否撤销待发货状态？"
                  @confirm="push_daifahuos_false(scope.row)"
                >
                  <el-button
                    slot="reference"
                    :disabled="
                      scope.row.logistics_status == 2 ||
                      scope.row.logistics_status == 3 ||
                      scope.row.logistics_status == 5
                    "
                    type="text"
                  >
                    取消待发货</el-button
                  >
                </el-popconfirm>
              </el-dropdown-item>

              <el-dropdown-item>
                <el-button
                  type="text"
                  @click="
                    chengpin_shanchu(scope.row.id, scope.row.order.order_number)">删除</el-button
                >
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button
                  type="text"
                  :disabled="scope.row.logistics_status == 3"
                  @click="set_cangku(scope.row)"
                  >转到备货库</el-button
                >
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <!-- <div
            style="
              display: grid;
              grid-template-rows: 1fr 1fr;
              grid-template-columns: 1fr 1fr 1fr;
              grid-gap: 10px;
              justify-items: center;
              align-items: center;
            "
          >
          </div> -->
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        @prev-click="prev"
        @next-click="next"
        :current-page.sync="pagination.page"
        :page-size="pagination.per_page"
        layout="total, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>

    <el-dialog
      title="调货"
      :visible.sync="ishuojia"
      width="60%"
      :close-on-click-modal="false"
      @close="close_dialog"
    >
      <div>
        <el-table :data="diaoList" stripe style="width: 100%" border>
          <el-table-column prop="delivery_date" label="交货日期" width="180">
          </el-table-column>
          <el-table-column label="客户名称" width="120">
            <template slot-scope="scope">
              {{ scope.row.customer ? scope.row.customer.customer_name : "" }}
            </template>
          </el-table-column>
          <el-table-column label="订单号" width="150">
            <template slot-scope="scope">
              {{ scope.row.order_number }}
            </template>
          </el-table-column>
          <el-table-column label="备注">
            <template slot-scope="scope">
              {{ scope.row.remark }}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="100" fixed="right">
            <template slot-scope="scope">
              <el-popconfirm
                confirm-button-text="好的"
                cancel-button-text="不用了"
                icon="el-icon-sort"
                icon-color="red"
                title="确定对此产品进行调货吗？"
                @confirm="add_product(scope.row)"
              >
                <el-button slot="reference" type="text" icon="el-icon-sort">
                  调货</el-button
                >
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>

        <div class="pagination">
          <el-pagination
            @size-change="handleSizeChange_diao"
            @current-change="handleCurrentChange_diao"
            background
            @prev-click="prev_diao"
            @next-click="next_diao"
            :current-page.sync="pagination_diao.page"
            :page-size="pagination_diao.per_page"
            layout="total, prev, pager, next"
            :total="total_diao"
          >
          </el-pagination>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="ishuojia = false" type="primary" size="small"
          >取 消</el-button
        >
      </span>
    </el-dialog>

    <el-dialog
      title="调货信息"
      :visible.sync="isjilu"
      width="40%"
      @close="close_dialog"
    >
      <div v-for="item in diaohuojilulist" :key="item.id">
        当前订单原客户
        <span style="font-weight: bold">{{
          item.order.customer.customer_name
        }}</span>
        在 {{ item.created_at }}与
        <span style="font-weight: bold">{{
          item.finish_order.customer.customer_name
        }}</span
        >的订单({{ item.order.order_number }})进行了调货
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isjilu = false">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="设置待发货"
      :visible.sync="isdfh"
      width="30%"
      @close="close_dialog_2"
    >
      <div>
        <el-row style="display: flex; align-items: center">
          <el-col :span="4"> 司机 </el-col>
          <el-col :span="20">
            <el-select v-model="driver_id" placeholder="请选择司机">
              <el-option
                v-for="item in driverList"
                :key="item.id"
                :label="item.company_name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-col>
        </el-row>
        <el-row style="display: flex; align-items: center;margin-top: 10px">
          <el-col :span="4"> 代发货备注 </el-col>
          <el-col :span="20">
             <el-input
              v-model="daifa_remark"
              placeholder="请输入代发货备注"
              style="width:200px; text-align: left"
            ></el-input>
          </el-col>
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isdfh = false" type="primary" size="small"
          >取 消</el-button
        >
        <el-button @click="push_daifahuo_box" type="primary" size="small"
          >确定</el-button
        >
      </span>
    </el-dialog>

    <el-dialog
      title="打印标签件数"
      :visible.sync="isbiaoqian"
      width="30%"
      @close="close_dialog_2"
    >
      <div>
        <el-row style="display: flex; align-items: center">
          <el-col :span="5">标签标题 </el-col>
          <el-col :span="20">
            <el-input
              v-model="biaoqian_name"
              placeholder="请输入标签标题"
              style="width: 100%; text-align: left"
            ></el-input>
          </el-col>
        </el-row>
        <el-row style="display: flex; align-items: center; margin-top: 10px">
          <el-col :span="5"> 件数 </el-col>
          <el-col :span="20">
            <el-input-number
              v-model="biaoqian_num"
              label="请输入件数"
              style="width: 100%; text-align: left"
            ></el-input-number>
          </el-col>
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isbiaoqian = false" type="primary" size="small"
          >取 消</el-button
        >
        <el-button @click="prints_box" type="primary" size="small"
          >确定</el-button
        >
      </span>
    </el-dialog>

    <el-dialog
      title="转到备货库"
      :visible.sync="isxiu_cangku"
      width="30%"
      @close="close_dialog_cangku"
    >
      <div>
        <el-row style="display: flex; align-items: center">
          <el-col :span="5">仓库 </el-col>
          <el-col :span="20">
            <el-select
              v-model="cangku.warehouse_id"
              @change="Warehouse_change"
              placeholder="请选择仓库"
            >
              <el-option
                v-for="item in WarehouseList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-col>
        </el-row>
        <el-row style="display: flex; align-items: center; margin-top: 15px">
          <el-col :span="5">货架 </el-col>
          <el-col :span="20">
            <el-select
              v-model="cangku.goods_shelf_id"
              @change="Warehouse_change_1"
              placeholder="请选择货架"
            >
              <el-option
                v-for="item in goods_shelfList"
                :key="item.goods_shelf_id"
                :label="item.name"
                :value="item.goods_shelf_id"
              >
              </el-option>
            </el-select>
          </el-col>
        </el-row>
        <!-- <el-row style="display: flex; align-items: center; margin-top: 15px">
          <el-col :span="5">仓位 </el-col>
          <el-col :span="20">
            <el-select
              v-model="cangku.warehouse_location_id"
              placeholder="请选择仓位"
            >
              <el-option
                v-for="item in cangwei_List"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-col>
        </el-row> -->
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isxiu_cangku = false" type="primary" size="small"
          >取 消</el-button
        >
        <el-button @click="push_cangkus" type="primary" size="small"
          >确定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      title="扣款"
      :visible.sync="isShow"
      width="30%"
      :before-close="handleClose"
    >
      <el-input v-model="money"></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="koukuan(1)">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="指派司机"
      :visible.sync="iszhipai_siji"
      width="30%"
      @close="close_dialog_siji"
    >
      <el-form>
        <el-form-item label="选择司机">
          <el-select v-model="driver_id" placeholder="请选择">
            <el-option
              v-for="item in YuanGongList"
              :key="item.id"
              :label="item.username"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="iszhipai_siji = false" type="primary" size="small"
          >取 消</el-button
        >
        <el-button @click="push_zhipaisiji" type="primary" size="small"
          >确定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      title="产品详情"
      v-if="isShow_product"
      :visible.sync="isShow_product"
      width="80%"
      :before-close="handleClose_product"
    >
      <el-table
        :data="dataList_product[0].order.order_second"
        v-horizontal-scroll="'always'"
        stripe
        style="width: 100%"
        border
      >
        <el-table-column type="expand">
          <template slot-scope="props_pid">
            <el-table :data="props_pid.row.order_second_pid"  v-if="props_pid.row.is_split == 1" style="margin-left:50px">
              <el-table-column label="产品名称" width="150">
                <template slot-scope="prop">
                  <span>{{
                    prop.row.product ? prop.row.product.product_name : ""}}</span>
                </template>
              </el-table-column>
              <el-table-column label="型号" width="150">
                <template slot-scope="prop">
                  <span>{{
                    prop.row.model_number
                      ? prop.row.model_number.model_number
                      : ""
                  }}</span>
                </template>
              </el-table-column>
             
              <el-table-column label="规格" width="150">
                <template slot-scope="prop">
                  <span>{{
                    prop.row.specification
                      ? prop.row.specification.specification
                      : ""
                  }}</span>
                </template>
              </el-table-column>
              <el-table-column label="颜色" width="150">
                <template slot-scope="prop">
                  <span>{{ prop.row.color ? prop.row.color.color : "" }}</span>
                </template>
              </el-table-column>
              <el-table-column label="尺寸" width="150" prop="work_size">
              </el-table-column>
              <el-table-column label="数量" width="150" prop="num">
              </el-table-column>
              <el-table-column label="备注" prop="remark"> </el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column label="类型">
          <template slot-scope="prop_s">
            <span>{{
              prop_s.row.type_id == 1
                ? "成品"
                : prop_s.row.type_id == 2
                ? "组件"
                : "外购"
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="产品">
          <template slot-scope="prop_s">
            <span>{{
              prop_s.row.product ? prop_s.row.product.product_name : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="型号">
          <template slot-scope="prop_s">
            <span>{{
              prop_s.row.model_number
                ? prop_s.row.model_number.model_number
                : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="规格">
          <template slot-scope="prop_s">
            <span>{{
              prop_s.row.specification
                ? prop_s.row.specification.specification
                : ""
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="颜色">
          <template slot-scope="prop_s">
            <span>{{ prop_s.row.color ? prop_s.row.color.color : "" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="尺寸">
          <template slot-scope="prop_s">
            <span>{{ prop_s.row.work_size }}</span>
          </template>
        </el-table-column>
        <el-table-column label="数量">
          <template slot-scope="prop_s">
            <span>{{ prop_s.row.num }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注">
          <template slot-scope="prop_s">
            <span>{{ prop_s.row.remark }}</span>
          </template>
        </el-table-column>
      </el-table>

      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose_product" type="primary" size="small"
          >确定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getFinishProductList,
  getStockAllocationList,
  stockAllocation,
  setDeliveryStatus,
  setStockUpStatus,
  deductMoney,
  getCustomerList,
  getModelNumberList,
  getProductList,
  updateFinishProductNum,
  delFinishProduct,
  getStockAllocationLog,
  getFinishProductList_exports,
  cancelDelivery,
  getWarehouseList,
  alterFinishProductWarehouse,
  getUserList,
  assignFinishProductDriver,
  getFinishProductDetail,
  getDriverList
} from "@/api/product/index";
import { myMixin } from '@/utils/mixin'
export default {
  inject: ["refresh"],
  mixins: [myMixin],
  data() {
    return {
      dataList_product: [],
      isShow_product: false,
      iszhipai_siji: false,
      isShow: false,
      money: 0,
      isxiu_cangku: false,
      cangku: {
        id: "",
        is_stock_up: 1,
        warehouse_id: "",
       
        goods_shelf_id: "",
      },
      maxnum: 0,
      loading: true,
      isbiaoqian: false,
      biaoqian_name: "",
      biaoqian_num: "",
      disableds: {},
      logistics_statuslist: [
        {
          status: 1,
          lable: "待发货",
        },
        {
          status: 2,
          lable: "未发货",
        },
      ],
      rows: {},
      isdfh: false,
      daifa_remark:"",
      finish_product_id:"",
      remark: "",
      fahuo_num: "",
      // 搜索
      ModelNumberLists: [],
      ModelNumberList: [],
      order_data: [],
      ser: {
        logistics_status: "",
        order_number: "",
        start_time: "",
        end_time: "",
        order_type:"finish_product",
      },
      CustomerList: [],
      productList: [],

      isdayin: false,
      isjilu: false,
      ishuojia: false,
      dataList: [],
      pagination: {
        per_page: 10,
        page: 1,
      },
      total: 0,
      dayinlist: [],
      dayinlist_biaoqian: [],
      diaoList: [],
      diaohuojilulist: [],
      datalists: [],
      pagination_diao: {
        per_page: 5,
        page: 1,
      },
      total_diao: 0,
      WarehouseList: [],
      goods_shelfList: [],
      cangwei_List: [],
      YuanGongList: [],
      c: "",
      siji_ids: [],
      driver_id:"",
      driverList:[]
    };
  },
  mounted() {
    this.getlist();
    this.getproduct();
    this.getModel();
    this.getCustomer();
    this.get_WarehouseList();
  },
  methods: {
    get_driverList(){
      getDriverList().then(res=>{
        if(res.code==200){
          this.driverList = res.data
        }
      })
    },
    handleClose_product() {
      this.isShow_product = false;
      this.dataList_product = [];
    },
    tableRowClassName() {
      return "height:60px;";
    },
    set_product(id) {
      getFinishProductDetail({ finish_product_id: id }).then((res) => {
        if (res.code == 200) {
          this.isShow_product = true;
          this.dataList_product = res.data;
        }
      });
    },
    formatterTime(data) {
      return /\d{4}-\d{1,2}-\d{1,2}/g.exec(data)[0];
    },
    close_dialog_siji() {
      this.driver_id = "";
      this.siji_ids = [];
    },
    push_zhipaisiji() {
      let obj = {
        finish_ids: this.siji_ids,
        driver_id: this.driver_id,
      };
      assignFinishProductDriver(obj).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功");
          this.getlist();
          this.iszhipai_siji = false;
        }
      });
    },
    get_YuanGongList() {
      getUserList().then((res) => {
        if (res.code == 200) {
          this.YuanGongList = [];
          res.data.data.forEach((item) => {
            if (item.role[0].name == "送货司机") {
              this.YuanGongList.push(item);
            }
          });
        }
      });
    },
    handleOpen(id) {
      this.id = id;
      this.isShow = true;
    },
    handleClose() {
      this.isShow = false;
      this.money = 0;
    },
    close_dialog_cangku() {
      this.cangku = {
        id: "",
        is_stock_up: 1,
        warehouse_id: "",
        goods_shelf_id: "",
      };
    },
    Warehouse_change(val) {
      console.log(val);
      this.WarehouseList.forEach((item) => {
        if (val == item.id) {
          this.goods_shelfList = item.children;
        }
      });
      console.log(this.goods_shelfList);
    },
    Warehouse_change_1(val) {
      console.log(val);
      this.goods_shelfList.forEach((item) => {
        if (val == item.id) {
          this.cangwei_List = item.children;
        }
      });
      console.log(this.cangwei_List);
    },
    get_WarehouseList() {
      getWarehouseList().then((res) => {
        if (res.code == 200) {
          this.WarehouseList = res.data.data;
        }
      });
    },
    push_cangkus() {
      if (this.cangku.warehouse_id == "") {
        this.$message.error("请选择仓库~");
        return false;
      }
      if (this.cangku.goods_shelf_id == "") {
        this.$message.error("请选择货架~");
        return false;
      }

      setStockUpStatus(this.cangku).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功");
          this.getlist();
          this.isxiu_cangku = false;
        }
      });
    },
    set_cangku(row) {
      this.cangku.id = row.id;
      // this.cangku.order_id = row.order_id;
      this.isxiu_cangku = true;
    },
    push_daifahuos_false(row) {
      setDeliveryStatus({ finish_product_id: row.id,logistics_status:2 }).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功~");
          this.getlist();
        }
      });
    },
    del_FinishProduct(id) {
      delFinishProduct({ finish_product_id: id }).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功~");
          this.getlist();
        }
      });
    },
    chengpin_shanchu(id, num) {
      this.$confirm("您确定删除订单号为：" + num + "的订单吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.del_FinishProduct(id);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    push_num_jianshu(id, num) {
      let obj = {
        id,
        num,
      };
      updateFinishProductNum(obj).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功~");
          this.disableds["disableds_" + id] = true;
        }
      });
      this.getlist();
    },
    dbclick_input(id) {
      console.log("222", id);
      this.$nextTick(() => {
        this.disableds["disableds_" + id] = false;
        this.$forceUpdate();
      });
    },
    koukuan_2(id,num) {
      let obj = {
        finish_product_id: id,
        is_deduct_money: num
      };
      deductMoney(obj)
        .then((res) => {
          if (res.code == 200) {
            this.$message.success("操作成功~");
            this.handleClose();
            this.dataList=[]
            this.getlist();
          }
        })
        .catch((e) => {
          console.error(e);
        });
    },
    koukuan(num) {
      let obj = {
        finish_product_id: this.id,
        is_deduct_money: num,
        money: this.money,
      };
      deductMoney(obj)
        .then((res) => {
          if (res.code == 200) {
            this.$message.success("操作成功~");
            this.handleClose();

            this.getlist();
          }
        })
        .catch((e) => {
          console.error(e);
        });
    },
    handleChange(val) {
      let num = this.rows.num - this.rows.to_be_sent_num;
      if (val == num) {
        this.fahuo_num = num - 1;
      }
    },
    // 指定查询
    search(type) {
      if (type == 0) {
        this.pagination.per_page = 10;
        this.pagination.page = 1;
      }
      getFinishProductList({ ...this.ser, ...this.pagination }).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data.data;
          this.total = res.data.total;
          if (type == 2) {
            if (res.data.data.length > 0) {
              this.$message.success("正在导出订单列表");
              this.exports_w();
            }
          }
        }
      });
    },
    // 导出
    exports_w() {
      let data = {
        ...this.ser,
        export: 1,
      };
      getFinishProductList_exports(data).then((res) => {
        //创建一个隐藏的a连接，
        const link = document.createElement("a");
        let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
        link.style.display = "none";
        //设置连接
        link.href = URL.createObjectURL(blob);
        link.download = "成品库";
        document.body.appendChild(link);
        //模拟点击事件
        link.click();
      });
    },
    searchreset() {
      this.ser = {
        logistics_status: "",
        order_number: "",
        start_time: "",
        end_time: "",
        order_type:"finish_product",
      };
      this.getlist();
    },
    //客户列表
    getCustomer() {
      getCustomerList({ per_page: 99999 }).then((res) => {
        if (res.code == 200) {
          this.CustomerList = res.data.data;
        }
      });
    },
    //产品列表
    getproduct() {
      getProductList().then((res) => {
        if (res.code == 200) {
          this.productList = res.data.data;
        }
      });
    },
    // 型号列表
    getModel() {
      getModelNumberList().then((res) => {
        if (res.code == 200) {
          this.ModelNumberLists = res.data.data;
        }
      });
    },
    order_data_change(val) {
      this.ser.start_time = val[0];
      this.ser.end_time = val[1];
    },
    product_id_change(val) {
      console.log(val);
      this.ser.model_number_id = "";
      this.get_producModel(val);
    },
    get_producModel(id) {
      getModelNumberList({
        product_id: id,
        field_list: "id,model_number",
        is_dropdown: 1,
      }).then((res) => {
        if (res.code == 200) {
          this.ModelNumberList = res.data.data;
        }
      });
    },
    beihuo(row) {
      setStockUpStatus({
        id: row.id,
        order_id: row.order_id,
        is_stock_up: 1,
      }).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "操作成功",
          });
          this.getlist();
        }
      });
    },
    push_daifahuos(id) {
      this.isdfh = true;
      this.finish_product_id=id
      this.get_driverList()
    },
    // 弹框确认
    push_daifahuo_box() {
      let obj = {
        finish_product_id:this.finish_product_id,
        logistics_status:1,
        driver_id:this.driver_id,
        daifa_remark:this.daifa_remark
      };
      setDeliveryStatus(obj).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "操作成功",
          });
          this.isdfh = false;
          this.daifa_remark=""
          this.getlist();
        }
      });
    },
    push_siji() {
      let ids = [];
      if (this.dayinlist.length > 0) {
        this.dayinlist.forEach((item) => {
          ids.push(item.id);
        });
      } else {
        this.$message({
          type: "error",
          message: "请勾选数据",
        });
        return false;
      }
      this.iszhipai_siji = true;
      this.siji_ids = ids;
      this.get_YuanGongList();
    },
    // 批量
    push_daifahuo() {
      let ids = [];
      if (this.dayinlist.length > 0) {
        this.dayinlist.forEach((item) => {
          ids.push(item.id);
        });
      } else {
        this.$message({
          type: "error",
          message: "请勾选数据",
        });
        return false;
      }

      setDeliveryStatus({ ids }).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "操作成功",
          });
          this.getlist();
        }
      });
    },
    diaohuojilu(row) {
      this.isjilu = true;
      getStockAllocationLog({ finish_product_id: row.id }).then((res) => {
        if (res.code == 200) {
          this.diaohuojilulist = res.data;
        }
      });
    },
    close_dialog_2() {
      this.rows = {};
      this.fahuo_num = "";
    },
    close_dialog() {
      this.finish_product_id = "";
      this.diaohuojilulist = [];
    },
    //调货确认
    add_product(row) {
      stockAllocation({
        order_id: row.id,
        finish_product_id: this.finish_product_id,
      }).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "操作成功",
          });
          this.getlist();
          this.ishuojia = false;
        }
      });
    },
    diaohuo(row) {
      if (row) {
        this.finish_product_id = row.id;
      }
      getStockAllocationList({
        id: this.finish_product_id,
        ...this.pagination_diao,
      }).then((res) => {
        if (res.code == 200) {
          if (res.data.data.length > 0) {
            this.ishuojia = true;
            this.diaoList = res.data.data;
            this.total_diao = res.data.total;
          } else {
            this.$message({
              type: "error",
              message: "暂无可调货订单",
            });
          }
        }
      });
    },
    // 获取成品库列表
    getlist() {
      getFinishProductList({
        ...this.pagination,
        ...this.ser,
        order_type: "finish_product",
      }).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data.data;
          this.dataList.forEach((item) => {
            const ob = "disableds_" + item.id;
            this.$set(this.disableds, ob, true);
          });
          this.total = res.data.total;
          this.toggleSelection(this.dayinlist);
          this.loading = false;
        }
      });
    },
    handleSelectionChange(val) {
      this.dayinlist = val;
      this.dayinlist_biaoqian = val;
    },
    //打印出货单
    print() {
      if (this.dayinlist.length > 0) {
        const routerurl = this.$router.resolve({
          name: "dayin",
          path: "/dayin",
          query: {
            data: JSON.stringify(this.dayinlist),
          },
        });
        window.open(routerurl.href, "_blank");
      } else {
        this.$message({
          type: "error",
          message: "请勾选数据",
        });
        return false;
      }
    },
    push_num_jianshus(id, num) {
      let obj = {
        id,
        num,
      };
      updateFinishProductNum(obj).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功~");
          this.isbiaoqian = false;
          this.dayinlist_biaoqian[0].num = this.biaoqian_num;
          this.dayinlist_biaoqian[0].biaoqian_name = this.biaoqian_name;
          const routerurl = this.$router.resolve({
            name: "biaoqian",
            path: "/biaoqian",
            query: {
              data: JSON.stringify(this.dayinlist_biaoqian),
            },
          });
          window.open(routerurl.href, "_blank");
          this.biaoqian_num = "";
          this.biaoqian_name = "";
          this.refresh();
        }
      });
    },
    //打印标签
    prints_box() {
      this.push_num_jianshus(this.dayinlist_biaoqian[0].id, this.biaoqian_num);
    },
    prints() {
      if (this.dayinlist_biaoqian.length == 1) {
        this.biaoqian_num = this.dayinlist_biaoqian[0].num;
        this.dayinlist_biaoqian[0].biaoqian_name = "";
        this.isbiaoqian = true;
      } else {
        if (this.dayinlist_biaoqian.length == 0) {
          this.$message({
            type: "error",
            message: "请勾选数据",
          });
          return false;
        }
        if (this.dayinlist_biaoqian.length > 1) {
          this.$message({
            type: "error",
            message: "只能选择一条数据",
          });
          return false;
        }
      }
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pagination.page = val;
      this.getlist();
    },
    prev() {
      this.pagination.page = this.pagination.page - 1;
      this.getlist();
    },
    next() {
      this.pagination.page = this.pagination.page + 1;
      this.getlist();
    },
    handleSizeChange_diao(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange_diao(val) {
      console.log(`当前页: ${val}`);
      this.pagination.page = val;
      this.diaohuo();
    },
    prev_diao() {
      this.pagination_diao.page = this.pagination_diao.page - 1;
      this.diaohuo();
    },
    next_diao() {
      this.pagination_diao.page = this.pagination_diao.page + 1;
      this.diaohuo();
    },
  },
};
</script>

<style scoped>
.el-dropdown-menu {
  text-align: center;
}

.el-dropdown-menu .el-button--text {
  width: 100%;
}
</style>
